using System;
using UnityEngine;

namespace IQIGame.Onigao.Framework
{
    [DisallowMultipleComponent]
    public class MonoDriver : FrameMonoModule
    {
        public event Action<float, float> updateEvent;
        public event Action fixedUpdateEvent;
        public event Action lateUpdateEvent;
        public event Action<bool> onApplicationPauseEvent;
        public event Action onApplicationQuitEvent;

        private void Update()
        {
            if (updateEvent != null)
            {
                updateEvent(Time.deltaTime, Time.unscaledDeltaTime);
            }
        }


        private void FixedUpdate()
        {
            if (fixedUpdateEvent != null)
            {
                fixedUpdateEvent();
            }
        }

        private void LateUpdate()
        {
            if (lateUpdateEvent != null)
            {
                lateUpdateEvent();
            }
        }

        private void OnApplicationPause(bool pause)
        {
            if (onApplicationPauseEvent != null)
            {
                onApplicationPauseEvent(pause);
            }
        }

        private void OnApplicationQuit()
        {
            updateEvent = null;
            lateUpdateEvent = null;
            fixedUpdateEvent = null;
            onApplicationPauseEvent = null;
            if (onApplicationQuitEvent != null)
            {
                onApplicationQuitEvent();
                onApplicationQuitEvent = null;
            }
        }

        protected override void OnInit()
        {

        }

        protected override void OnEnterGame()
        {

        }

        protected override void OnShutdown()
        {

        }

        protected override bool ignoreMonoMsgCheck()
        {
            return true;
        }
    }
}
